package com.sky.controller.user;

import com.sky.constant.RedisKeyConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 山顶洞人郑某
 * @className SetmealController.java
 * @date 2024 02 07
 */
@RequestMapping("/user/setmeal")
@RestController("userSetmealController")
@Api(tags = "用户端套餐管理")
@Slf4j
public class SetmealController {

    @Autowired
    private DishService dishService;
    @Autowired
    private SetmealService setmealService;

    /**
     * 根据分类id查询分类下的套餐
     * @param categoryId
     * @return
     */
    @Cacheable(cacheNames = RedisKeyConstant.SETMEAL,key = "#categoryId")
    @GetMapping("/list")
    @ApiOperation(value = "用户根据分类查询菜品信息")
    public Result<List<Setmeal>> list(Long categoryId){
      log.info("查询的套餐分类id为{}",categoryId);
      List<Setmeal> list = setmealService.list(categoryId);
      log.info("分类下的套餐信息为：{}",list);
      return Result.success(list);
    }

    /**
     * 根据套餐id查询套餐下的菜品信息
     * @param id
     * @return
     */
    //@Cacheable(cacheNames = "setmeal_dish",key = "#id")
    @ApiOperation(value = "根据套餐id查询套餐下的菜品信息")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> dish(@PathVariable Long id){
         log.info("套餐id{}",id);
         List<DishItemVO> list = dishService.getListByCategoryId(id);
         log.info("当前套餐所包含的菜品信息为：{}",list);
         return Result.success(list);
    }
}
